VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "clsWindow"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
'--------------------------------------------------------------------------
' Class clsWindow shows how to create and manage window entirely from VB
'--------------------------------------------------------------------------

Option Explicit

Implements IsgMessageSink
Implements IsgPaintSink

Private mWnd As sgWindow.Window
Private mwndRect As RECT



Public Sub Create(hParent&, sText$, id&, x&, y&, width&, height&, style&)
   ' Enable message processing
   mWnd.EnableMessage wm_ALL, True
   
   ' Get rid of attached window
   mWnd.HWND = 0
   
   ' Create new window
   mWnd.Create "", sText, style, 0, x, y, width, height, hParent, id
   mWnd.Tag = sText
End Sub

Private Sub Class_Initialize()
   Set mWnd = New sgWindow.Window
   mWnd.SetMessageCallback Me
   mWnd.SetPaintCallback Me
End Sub

Private Sub Class_Terminate()
   mWnd.HWND = 0
   Set mWnd = Nothing
End Sub

Private Sub IsgMessageSink_Message(ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long, ByRef result As Long)
   Select Case msg
      Case wm_NCCREATE
         result = 1
        
      Case wm_SIZE
         mwndRect.left = 0
         mwndRect.top = 0
         mwndRect.right = sgWindow.LowWord(lParam)
         mwndRect.bottom = sgWindow.HighWord(lParam)
         result = 0
         
      Case Else
         result = mWnd.CallWindowProc(msg, wParam, lParam)
   End Select
End Sub

Private Sub IsgPaintSink_ClientPaint(ByVal hdc As Long, ByVal left As Long, ByVal top As Long, ByVal right As Long, ByVal bottom As Long)
   Dim rcText As RECT
   
   'GetClientRect mWnd.HWND, rc
   Rectangle hdc, 0, 0, mwndRect.right, mwndRect.bottom
   
   ' Calculate text rectangle
   rcText = mwndRect
   DrawText hdc, mWnd.Tag, -1, rcText, DT_CENTER + DT_VCENTER + DT_WORDBREAK + DT_CALCRECT
   Dim nTextHeight%, nTextWidth%
   nTextHeight = rcText.bottom - rcText.top
   nTextWidth = rcText.right - rcText.left
   rcText.top = (mwndRect.bottom - nTextHeight) / 2
   rcText.bottom = rcText.top + nTextHeight
   rcText.left = (mwndRect.right - nTextWidth) / 2
   rcText.right = rcText.left + nTextWidth
   
   ' Draw text
   DrawText hdc, mWnd.Tag, -1, rcText, DT_CENTER + DT_VCENTER + DT_WORDBREAK
End Sub

Private Sub IsgPaintSink_FramePaint(ByVal hdc As Long)
   ' Do nothing
End Sub

Private Function IsgPaintSink_GetFlags() As sgWindow.PaintFlag
   IsgPaintSink_GetFlags = pfClientPaint
End Function
